<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>sem管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="${re.contextPath}/plugin/layui/css/layui.css">
    <link rel="stylesheet" href="${re.contextPath}/plugin/lenos/main.css">
    <link rel="stylesheet" href="${re.contextPath}/plugin/formSelects/formSelects-v4.css"/>

    <link href="${re.contextPath}/plugin/assets/global/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
    <link href="${re.contextPath}/plugin/assets/global/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <link href="${re.contextPath}/plugin/assets/global/css/components.min.css" rel="stylesheet" id="style_components" type="text/css" />
    <link href="${re.contextPath}/plugin/assets/global/css/plugins.min.css" rel="stylesheet" type="text/css" />
    <link href="${re.contextPath}/plugin/assets/global/plugins/datatables/datatables.min.css" rel="stylesheet" type="text/css" />
    <link href="${re.contextPath}/plugin/assets/global/plugins/datatables/plugins/bootstrap/datatables.bootstrap.css" rel="stylesheet" type="text/css" />

    <script type="text/javascript" src="${re.contextPath}/plugin/laydate/laydate.js"></script>
    <script type="text/javascript" src="${re.contextPath}/plugin/jquery/jquery-3.2.1.min.js"></script>
    <script type="text/javascript" src="${re.contextPath}/plugin/layui/layui.all.js" charset="utf-8"></script>
    <script type="text/javascript" src="${re.contextPath}/plugin/tools/tool.js"></script>
    <script type="text/javascript" src="${re.contextPath}/plugin/formSelects/formSelects-v4.js"></script>

    <style>
        .xm-select-parent {
            width: 300px;
        }
    </style>
    <style>
        .fl{
            float:left;
            margin-right:15px;
        }
        .box_btns {
            z-index: 17;
            position: absolute;
            top:0;
            left: 75px;
            width: 625px;
            background-color: #f1f3fa;
            display: none;
        }

        .box_btns>label {
            float: left;
            width: 151px;
            height: 30px;
            background-color: #fff;
            overflow: hidden;
            line-height: 30px;
            text-align: left;
            text-indent: 10px;
            border: 2px solid #dfe1e6;
        }
        .btn_zdy{
            width:74px;
            height:34px;
            border:1px solid #666;
            line-height: 34px;
            text-align: center;
        }
        #jia{
            cursor: pointer;
            user-select: none;
        }
        #jia:hover{
            background-color: burlywood;
            color: #fff;
            transition: .45s;
        }
        .box_btns>label:nth-child(odd) {
            margin-right: 5px;
            margin-left: 4px;
            margin-top: 5px;
        }
        .box_btns>label:nth-child(even) {
            /*margin-right: 5px;*/
            /*margin-left: 4px;*/
            margin-top: 5px;
        }

        #btn_resover{
            margin-right:121px;
        }


        .box_btns>label>input {
            position: relative;
            top: 2px;
            margin-right: 5px;
        }

        /* define bootstrap 5 columns */
        .picc-xs-1-5,
        .picc-sm-1-5,
        .picc-md-1-5,
        .picc-lg-1-5 {
            position: relative;
            min-height: 1px;
            padding-right: 10px;
            padding-left: 10px;
        }

        .picc-xs-1-5 {
            width: 20%;
            float: left;
        }

        @media (min-width: 768px) {
            .picc-sm-1-5 {
                width: 20%;
                float: left;
            }
        }
        @media (min-width: 992px) {
            .picc-md-1-5 {
                width: 20%;
                float: left;
            }
        }
        @media (min-width: 1200px) {
            .picc-lg-1-5 {
                width: 20%;
                float: left;
            }
        }
        .fl{
            float: left;
        }
        .mg-l{
            margin-left:40px;
            margin-top:5px;
            font-weight:bold;
        }
        .font_picc{
            color:rgb(0,0,0);
            border:0;
            background-color:rgb(255,255,255);
            font-size: 14px;
            color: #AAB5BC;
            font-weight: 600;
            text-transform: uppercase;
            width:8px;
            height:20px;
            padding-top:0px;
            padding-left:0px;
            text-align:center;
        }

    </style>
</head>

<body>
<div class="lenos-search" style="overflow: inherit; height: 140px;">
    <div class="select">
        <div class="layui-form">
            <div style="width: 400px; display: inline-block; vertical-align: top;">
                <div class="layui-form">
                    <select id="MEDIA_CHANNEL" name="MEDIA_CHANNEL" xm-select="MEDIA_CHANNEL" lay-verify="MEDIA_CHANNEL">
                        <option value="">请选择媒体</option>
                    </select>
                </div>
            </div>
            <div style="width: 400px; display: inline-block; vertical-align: top;">
                <div class="layui-form">
                    <select id="ACCOUNT_TYPE" name="ACCOUNT_TYPE" xm-select="ACCOUNT_TYPE" lay-verify="ACCOUNT_TYPE">
                        <option value="">请选择账户</option>
                    </select>
                </div>
            </div>
            <div style="width: 400px; display: inline-block; vertical-align: top;">
                <div class="layui-form">
                    <select id="INSURANCE_TYPE" name="INSURANCE_TYPE" xm-select="INSURANCE_TYPE" lay-verify="INSURANCE_TYPE">
                        <option value="">请选择险种</option>
                    </select>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-col-md4">
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <label class="layui-form-label" style="width: 100px;">数据来源</label>
                <div class="layui-input-block" style="width: 120px;">
                    <select id="equipmentType" name="equipmentType" lay-verify="required">
                        <#--<option value="">请选择...</option>-->
                        <option value="1">PC</option>
                        <option value="2">WAP</option>
                    </select>
                </div>
            </div>
        </form>
    </div>
    <div class="layui-col-md4">
        <label class="layui-form-label" style="width: 100px;"> 日期范围 </label>
        <input type="text" class="layui-input" id="dateInput" placeholder=" - " style="width:200px; height: 30px;" readonly="readonly">
    </div>
    <div class="layui-col-md4">
      <button class="select-on layui-btn layui-btn-sm" onclick="search()" data-type="select" style="float: left;"><i class="layui-icon"></i>
      </button>
      <button class="layui-btn layui-btn-sm icon-position-button" onclick="search()" id="refresh" style="float: right;"
              data-type="reload">
          <i class="layui-icon">ဂ</i>
      </button>
    </div>
    <div style="clear: both;"></div>
    <div class="layui-col-md12" style="border-bottom:0px;">
    <#--<div class="portlet light bordered">-->
        <div class="btn_data" id="btn_two">
            <#--<button class="btn blue fl" onclick="listKeyWordData()">关键词</button>-->
            <#--<button class="btn blue fl" onclick="listCreativityData()">创意</button>-->
            <div class="row fl">
                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                    <div id="typeBtu" class="btn-group">
                    </div>
                    <div style="clear: both;"></div>
                </div>
            </div>
            <#--<button class="btn blue" style="float: right;" onclick="exportExcel()">导出excel</button>-->
        </div>

    <#--</div>-->
    </div>
</div>

<table id="searchWordList" style="margin-top: 100px;" class="layui-hide" lay-filter="searchWord"></table>

<script type="text/html" id="toolbar">
</script>

<script>
    var pageData = {
        a:1,
        dateStr: null,
        equipmentType: "",
        mediaCompany: "",
        accountType: "",
        insuranceType: "",
        plugin_config: {
            format: 'yyyy-mm-dd',
            todayBtn: 'linked',
            todayHighlight: true,
            autoclose: true
        },
    }
    var btns = [
        {id: "0", name: "日期", db_name: "ot.dt", value: "ATCharts", bm: "dt"},
        {id: "1", name: "关键词", db_name: "ot.keyword", value: "ATCharts", bm: "keyword"},
        {id: "2", name: "推广组", db_name: "ot.adgroup_name", value: "ATCharts", bm: "adgroup_name"},
        {id: "3", name: "推广计划", db_name: "ot.campaign_name", value: "ATCharts", bm: "campaign_name"},
        {id: "4", name: "cmpid", db_name: "ot.cmpid", value: "ATCharts", bm: "cmpid"},
        {id: "5", name: "代理公司", db_name: "dd.channel_cn", value: "ATCharts", bm: "agent_company"},
        {id: "6", name: "媒体类型", db_name: "d.channel_cn", value: "ATCharts", bm: "media_type"},
        {id: "7", name: "媒体", db_name: "c.channel_cn", value: "ATCharts", bm: "media_channel"},
        {id: "8", name: "账户", db_name: "ddd.channel_cn", value: "ATCharts", bm: "campaign_account"},
        {id: "9", name: "创意/词性", db_name: "dddd.channel_cn", value: "ATCharts", bm: "campaign_word_type"},
        {id: "10", name: "险种/活动", db_name: "ddddd.channel_cn", value: "ATCharts", bm: "campaign_insurance_type"},
        {id:'11',name:'曝光量',db_name:'COALESCE(sum(ot.impression),0)',value:'ATCharts',bm:'impression'},
        {id:'12',name:'点击量',db_name:'COALESCE(sum(ot.click),0)',value:'ATCharts',bm:'click'},
        {id:'13',name:'点击率',db_name:'COALESCE(ROUND(sum(ot.click)/sum(ot.impression)*100,2),0)',value:'ATCharts',bm:'avg_click_count'},
        {id:'14',name:'点击成本CPC',db_name:'COALESCE(ROUND(sum(ot.cost)/sum(ot.click),2),0)',value:'ATCharts',bm:'avg_click_cost'},
        {id:'15',name:'总费用',db_name:'COALESCE(sum(ot.cost),0)',value:'ATCharts',bm:'cost'},
        {id:'16',name:'浏览量',db_name:'COALESCE(sum(ot.page_views),0)',value:'ATCharts',bm:'page_views'},
        {id:'17',name:'访问量',db_name:'COALESCE(sum(ot.visits),0)',value:'ATCharts',bm:'visits'},
        {id:'18',name:'访问成本',db_name:'COALESCE(ROUND(sum(ot.cost)/sum(ot.visits),2),0)',value:'ATCharts',bm:'avg_visits_cost'},
        {id:'19',name:'访客量',db_name:'COALESCE(sum(ot.visitors),0)',value:'ATCharts',bm:'visitors'},
        {id:'20',name:'注册量',db_name:'COALESCE(sum(ot.registertion_count),0)',value:'ATCharts',bm:'registertion_count'},
        {id:'21',name:'车险信息填写页访问量',db_name:'COALESCE(sum(ot.car_insurance_visits),0)',value:'ATCharts',bm:'car_insurance_visits'},
        {id:'22',name:'非车险信息填写页访问量',db_name:'COALESCE(sum(ot.none_car_insurance_visits),0)',value:'ATCharts',bm:'none_car_insurance_visits'},
        {id:'23',name:'名单量',db_name:'COALESCE(sum(ot.name_lists),0)',value:'ATCharts',bm:'name_lists'},
        {id:'24',name:'名单成本CPA',db_name:'COALESCE(ROUND(sum(ot.cost)/sum(ot.name_lists),2),0)',value:'ATCharts',bm:'avg_name_lists_cost'},
        {id:'25',name:'名单量转化率',db_name:'COALESCE(ROUND(sum(ot.name_lists)/sum(ot.visits)*100,2),0)',value:'ATCharts',bm:'name_lists_rate'},
        {id:'26',name:'平均访问时长',db_name:'COALESCE(ROUND(sum(ot.visits_duration)/sum(ot.visits),2),0)',value:'ATCharts',bm:'avg_visits_time'},
        {id:'27',name:'跳出率',db_name:'COALESCE(ROUND(sum(ot.bounces)/sum(ot.entries)*100,2),0)',value:'ATCharts',bm:'bounces_rate'},
        {id:'28',name:'提交订单量',db_name:'COALESCE(sum(ot.orders),0)',value:'ATCharts',bm:'orders'},
        {id:'29',name:'车险提交订单量',db_name:'COALESCE(sum(ot.car_order),0)',value:'ATCharts',bm:'car_order'},
        {id:'30',name:'非车险提交订单量',db_name:'COALESCE(sum(ot.nocar_order),0)',value:'ATCharts',bm:'nocar_order'},
        {id:'31',name:'提交订单转化率',db_name:'COALESCE(ROUND(sum(ot.orders)/sum(ot.name_lists)*100,2),0)',value:'ATCharts',bm:'orders_rate'},
        {id:'32',name:'提交保费',db_name:'COALESCE(sum(ot.revenue),0)',value:'ATCharts',bm:'revenue'},
        {id:'33',name:'车险提交保费',db_name:'COALESCE(sum(ot.car_revenue),0)',value:'ATCharts',bm:'car_revenue'},
        {id:'34',name:'非车险提交保费',db_name:'COALESCE(sum(ot.nocar_revenue),0)',value:'ATCharts',bm:'nocar_revenue'},
        {id:'35',name:'投产比ROI',db_name:'COALESCE(ROUND(sum(ot.revenue)/sum(ot.cost),2),0)',value:'ATCharts',bm:'revenue_cost'},
        {id:'36',name:'成交订单',db_name:'COALESCE(sum(ot.actual_order),0)',value:'ATCharts',bm:'actual_order'},
        {id:'37',name:'成交订单转化率',db_name:'COALESCE(ROUND(sum(ot.actual_order)/sum(ot.name_lists)*100,2),0)',value:'ATCharts',bm:'actual_order_rate'},
        {id:'38',name:'成交保费',db_name:'COALESCE(sum(ot.actual_revenue),0)',value:'ATCharts',bm:'actual_revenue'},
    ];
    var formSelects = layui.formSelects;
    formSelects.render();
    //Demo
    layui.use('form', function(){
        var form = layui.form;
        form.render();
        //监听提交
        form.on('submit(formDemo)', function(data){
            layer.msg(JSON.stringify(data.field));
            return false;
        });
    });

    // 关键词数据报表
    function initKeyWordReportList(){
        var arr_btns_ids=JSON.parse(window.localStorage.more_btns_stor);/* 获取localstorage */
        window.localStorage.more_btns_stor=JSON.stringify(arr_btns_ids);
        var btnsdata = getBtns(arr_btns_ids, btns);
        var ajax_data = format_localstorage_data(btnsdata);

        var timeVal = $("#dateInput").val();
        pageData.dateStr = timeVal;
        pageData.equipmentType = $("#equipmentType").val();
        pageData.mediaCompany = formSelects.value('MEDIA_CHANNEL', 'valStr');
        pageData.accountType = formSelects.value('ACCOUNT_TYPE', 'valStr');
        pageData.insuranceType = formSelects.value('INSURANCE_TYPE', 'valStr');

        // 列改变了，需要清空table
        var formatTableTitle = format_table_title(arr_btns_ids, btns);
        var table = layui.table;
        table.render({
            elem: '#searchWordList'
            , url: 'loadKeyWordTableData'
            , method: 'POST'
            , cols: [formatTableTitle]
            , loading : true
            , limit: 5000
            , toolbar: "#toolbar"
            , defaultToolbar: ['filter', 'print', 'exports']
            , page: true
            , autoSort: true
            , where: {
                dateStr: pageData.dateStr,
                equipmentType: pageData.equipmentType,
                mediaCompany: pageData.mediaCompany,
                accountType: pageData.accountType,
                insuranceType: pageData.insuranceType,
                dateType: null,
                ajax_data: ajax_data
            }
        });

    }

    // 获取渠道字典
    function dictionary(channelType){
        $.ajax({
            type: "POST",
            url: "${re.contextPath}/market/loadsDictionaryByType",
            data: {'channelType':channelType},  //传入组装的参数
            async: false,
            dataType: "json",
            success: function (result) {
//                var option='';
                for(var index in result.data){
                    for(var key in result.data[index]){
//                        option += "<option value='"+key+"'>"+result.data[index][key]+"</option>";
                        $("#"+channelType+"").append(new Option(result.data[index][key], key));
                    }
                }
                formSelects.render();
            }
        });
    }

    // 搜索按钮查询事件
    function search() {
        initKeyWordReportList();
    }

    /* 获取数组 */
    function getIsArray(arr,value){
        for(var i=0;i<arr.length;i++){
            if(arr[i]==value){
                return true;
            }
        }
        return false;
    }

    // 创建自定义列
    function createCheck($btn2,$divbig,checkoption){
        var arr_btns_id;
        arr_btns_id=JSON.parse(window.localStorage.more_btns_stor);
        var str_btn='';
        for (var i=0;i<checkoption.length;i++){
            if(getIsArray(arr_btns_id,i)){
                str_btn+="<label><input type='checkbox' class='arrs_btn' id="+checkoption[i].id+" checked='true'>"+checkoption[i].name+"</label>";
            }else{
                str_btn+="<label><input type='checkbox' class='arrs_btn' id="+checkoption[i].id+">"+checkoption[i].name+"</label>";
            }
        }
        $divbig.append(str_btn)
        var $arrs_Btns = $("#btn_ok");
        var $arrs_Btn = $(".arrs_btn");
        //点击全选
        $('#btn_all').on('click',function(){
            $('.box_btns>label>input').prop("checked", true)
        });
        //点击反选
        $('#btn_resover').on('click',function(){
            $('.box_btns>label>input').prop("checked",false)
        });

        /* 点击复选框添加的按钮 */
        $arrs_Btns.on('click',function(event){
            if(pageData.a==0){
                $divbig.css("display","none");
                pageData.a=1;
            }else if(pageData.a==1){
                $divbig.css("display","block");
                pageData.a=0;
            }else{
                $divbig.css("display","none");
                pageData.a=1;
            };
            var timeVal = document.getElementById("dateInput").value;
            pageData.dateStr = timeVal;
            pageData.equipmentType = $("#equipmentType").val()+"";
            pageData.mediaCompany = $("#mediaCompany").val()+"";
            pageData.accountType = $("#accountType").val()+"";
            pageData.insuranceType = $("#insuranceType").val()+"";
            arr_btns_id=[];
            data_list=[];
            for(var i=0;i<$arrs_Btn.length;i++){
                if($arrs_Btn[i].checked==true){
                    arr_btns_id.push($arrs_Btn[i].id)
                }
            }
            var a = arr_btns_id.indexOf("0");
            var b = arr_btns_id.indexOf("1");
            var c = arr_btns_id.indexOf("2");
            var d = arr_btns_id.indexOf("3");
            var e = arr_btns_id.indexOf("4");
            var f = arr_btns_id.indexOf("5");
            var g = arr_btns_id.indexOf("6");
            var h = arr_btns_id.indexOf("7");
            var i = arr_btns_id.indexOf("8");
            var j = arr_btns_id.indexOf("9");
            var k = arr_btns_id.indexOf("10");

            if(a+b+c+d+e+f+g+h+i+j+k == -11){
                alert("必须选中不少于一项维度!");
                return false;
            }

            var a1 = arr_btns_id.indexOf("11");
            var b1 = arr_btns_id.indexOf("12");
            var c1 = arr_btns_id.indexOf("13");
            var d1 = arr_btns_id.indexOf("14");
            var e1 = arr_btns_id.indexOf("15");
            var f1 = arr_btns_id.indexOf("16");
            var g1 = arr_btns_id.indexOf("17");
            var h1 = arr_btns_id.indexOf("18");
            var i1 = arr_btns_id.indexOf("19");
            var j1 = arr_btns_id.indexOf("20");
            var k1 = arr_btns_id.indexOf("21");
            var l1 = arr_btns_id.indexOf("22");
            var m1 = arr_btns_id.indexOf("23");
            var n1 = arr_btns_id.indexOf("24");
            var o1 = arr_btns_id.indexOf("25");
            var p1 = arr_btns_id.indexOf("26");
            var q1 = arr_btns_id.indexOf("27");
            var r1 = arr_btns_id.indexOf("28");
            var s1 = arr_btns_id.indexOf("29");
            var t1 = arr_btns_id.indexOf("30");
            var u1 = arr_btns_id.indexOf("31");
            var v1 = arr_btns_id.indexOf("32");
            var w1 = arr_btns_id.indexOf("33");
            var x1 = arr_btns_id.indexOf("34");
            var y1 = arr_btns_id.indexOf("35");
            var z1 = arr_btns_id.indexOf("36");
            var zz1 = arr_btns_id.indexOf("37");
            var zzz1 = arr_btns_id.indexOf("38");

            if(a1+b1+c1+d1+e1+f1+g1+h1+i1+j1+k1+l1+m1+n1+o1+p1+q1+r1+s1+t1+u1+v1+w1+x1+y1+z1+zz1+zzz1 == -28){
                alert("必须选中不少于一项量度!!");
                return false;
            }
            window.localStorage.more_btns_stor=JSON.stringify(arr_btns_id);
            var arr_btns_idsa=JSON.parse(window.localStorage.more_btns_stor);/* 获取localstorage */
//                    window.localStorage.more_btns_stor=JSON.stringify(arr_btns_idsa);
//                    var btnsdatab = getBtns(arr_btns_idsa, checkoption);
//                    var ajax_data = format_localstorage_data(btnsdatab);
            initKeyWordReportList();
            return false;
        })
    }

    /* 创建“+”按钮   */
    function create_jia_btns(checkoption){

        $("#big_wrap").remove();

        var $btn2=$("<div id='big_wrap' style='position:relative;'></div>");
        var $divbig=$("<div class='box_btns'><div class='btn blue fl' id='btn_ok'>确定</div><div class='btn blue fl' id='btn_all'>全选</div><div class='btn blue fl' id='btn_resover'>清空</div></div>");
        $btn2.attr("class","btn_zdy");
        $btn2.html("<div id='jia'>自定义列</div>");
        $("#typeBtu").append($btn2);
        $btn2.append($divbig);
        createCheck($btn2,$divbig,checkoption);
        $('#jia').click(function(event){
            var e = e ||event;
            var label=label;
            if(pageData.a==0){
                $divbig.css("display","none");
                pageData.a=1;
            }else if(pageData.a==1){
                $divbig.css("display","block");
                pageData.a=0;
            }else{
                $divbig.css("display","none");
                pageData.a=1;
            }
        })
    }

    function getBtns(ids, btnsoption){
        var selectBtns=[]
        for(var i=0;i<btnsoption.length;i++){
            for(var j=0;j<ids.length;j++){
                if(btnsoption[i].id == parseInt(ids[j])){
                    selectBtns.push(btnsoption[i]);
                }
            }
        }
        return selectBtns;
    }

    /* 初始化“+”按钮函数 */
    function initBtns(){

        if(window.localStorage.more_btns_stor){
            window.localStorage.more_btns_stor=window.localStorage.more_btns_stor;
        }else{
            window.localStorage.more_btns_stor='[0,11,12,15,17,23,28,30]';
        }
        create_jia_btns(btns);

    }

    // 格式化localstorage数据
    function format_localstorage_data(list) {
            var data_big_list=list;
            var column_name=list;
            var data_big_bigs=[];
            var ajax_data=[];
            if(data_big_list==null){
                data_big_bigs=[ { "name": "keyword"}, { "name": "adgroup_name" },{ "name": "campaign_name" },{ "name": "cmpid" },{ "name": "channel_company" },
                    { "name": "impression" },{ "name": "click" },{ "name": "avg_click_count" },{ "name": "avg_click_cost" },{ "name": "cost" }];
                wck(data_big_bigs,ajax_data);
            }else{
                data_big_bigs=get_arr_obj(data_big_list)
                wck(data_big_bigs,ajax_data);
            }
            return JSON.stringify(ajax_data);
        }

    // 格式化table表头
    function format_table_title(ids, btnsoption){
        var selectBtns=[]
        for(var i=0;i<btnsoption.length;i++){
            for(var j=0;j<ids.length;j++){
                if(btnsoption[i].id == parseInt(ids[j])){
                    selectBtns.push({title:btnsoption[i].name, field: btnsoption[i].bm, width: 150});
                }
            }
        }
        return selectBtns;
    }

    /////////////////////           Tools            //////////////////////////////////////////////////////

    // 初始化日期控件
    function initDate() {
        //日期范围
        laydate.render({
            elem: '#dateInput'
            ,range: true,
            max: -1,
            showBottom :false,    //关闭底部框 去掉取消、确定、清空按钮
            change: function(value, date, endDate){
                $("#dateInput").val(value);
                if($(".layui-laydate").length){
                    $(".layui-laydate").remove();
                }
            }
        });

        var e1 = document.getElementById("dateInput");
        var day1 = new Date();
        var day2 = new Date();
        day1.setDate(day1.getDate() - 6);
        day2.setDate(day2.getDate());
        var s1 = formatDate(day1);
        var s2 = formatDate(day2);
        e1.value = s1+" - "+s2;
        var timeVal = document.getElementById("dateInput").value;
        pageData.dateStr = timeVal;
    }

    // 格式化日期
    function formatDate (date) {
        var y = date.getFullYear();
        var m = date.getMonth() + 1;
        m = m < 10 ? '0' + m : m;
        var d = date.getDate();
        d = d < 10 ? ('0' + d) : d;
        return y + '-' + m + '-' + d;
    };

    /* 获取一个新数组 */
    function get_arr_obj(data) {
        return data.map(function (item) {
            return {
                name: item.bm,
                title:item.name
            };
        });
    }

    /* 对象数组转化成数组方法 */
    function wck(item,ele) {
        for(var i=0;i< item.length;i++){
            ele.push(item[i].name);
        }
    }

    //////////////////////////////////////////////////////////////////////////////////////////////////////
</script>
<script>
    layui.use(['table','form'], function () {
        initDate();
        initBtns();
        dictionary("ACCOUNT_TYPE");
        dictionary("INSURANCE_TYPE");
        dictionary("MEDIA_CHANNEL");
        layui.form.render();
        var table = layui.table;
        initKeyWordReportList();


        //监听工具条
        table.on('tool(user)', function (obj) {
            var data = obj.data;
            if (obj.event === 'detail') {
                detail('编辑角色', 'updateRole?id=' + data.id, 700, 450);
            } else if (obj.event === 'del') {
                layer.confirm('确定删除角色[<label style="color: #00AA91;">' + data.roleName + '</label>]?', function(){
                    del(data.id);
                });
            } else if (obj.event === 'edit') {
                update('编辑角色', 'updateRole?id=' + data.id, 700, 450);
            }
        });

    });


</script>
</body>

</html>
